<?php
/**
 * 备货产品sku比例
 * (model)
 */
namespace App\Models\SsBasic;


use App\Models\Basics\SysArea;
use App\Models\Product\ProductSku;
use App\Models\SsBasic\StockupAreaSku;
use Illuminate\Database\Eloquent\Model;

class StockupAreaSkuRatio extends Model{

    protected $table = 's_stockup_area_sku_ratio';

    protected $guarded = [];

    //public function area(){
    //    return $this->belongsTo(SysArea::class,'area_id');
    //}
    //
    //public function sku(){
    //    return $this->belongsTo(ProductSku::class,'psku_id');
    //}

    public function area_sku(){
        return $this->belongsTo(StockupAreaSku::class, 'area_psku', 'area_psku');
    }

    public static function getSkuRatio($key){
        $ratio = self::query()
            ->where('area_psku',$key)
            ->value('ratio');
        return $ratio ?: 0;
    }
}
